package com.zhuge_new.Activity;



import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.maning.mndialoglibrary.MToast;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionListener;
import com.zhuge_new.Base.BaseActivity;
import com.zhuge_new.MainActivity;
import com.zhuge_new.R;
import com.zhuge_new.untils.ActivityStack;
import com.zhuge_new.untils.PreferencesUtils;
import com.zhuge_new.untils.StatusBarUtil;
import com.zhuge_new.untils.TimerUtil;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;


/**
 * Created by lenovo on 2018-08-24.
 */

public class GuideActivity extends BaseActivity implements View.OnClickListener {

    private String unionid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*requestWindowFeature(Window.FEATURE_NO_TITLE);*/
        StatusBarUtil.transparencyBar(GuideActivity.this);
        setContentView(R.layout.activity_guide);

        initData();

    }

    private void initData() {
        AndPermission.with(GuideActivity.this)
                .permission(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.CAMERA)
                .callback(new PermissionListener() {
                    @Override
                    public void onSucceed(int requestCode, @NonNull List<String> grantPermissions) {
                        initView();
                    }

                    @Override
                    public void onFailed(int requestCode, @NonNull List<String> deniedPermissions) {
                        MToast.makeTextShort(baseContext,"请求权限被拒绝" ).show();
                        onBackPressed();
                    }
                })
                .start();
    }

    private void initView() {
        TextView guide_skip=findViewById(R.id.guide_skip);
        unionid = PreferencesUtils.getString(GuideActivity.this,"unionid","");
        TimerUtil timerUtil =new TimerUtil(guide_skip,4000,1000,"跳过","秒后跳过");
        guide_skip.setOnClickListener(this);
        timerUtil.start();


        final Intent intent=new Intent(this,LoginActivity.class);
        final Intent intent1=new Intent(this, MainActivity.class);
        Timer timer=new Timer();
        TimerTask task=new TimerTask() {
            @Override
            public void run() {
                if (unionid.isEmpty()){
                    startActivity(intent);
                }else {
                    startActivity(intent1);
                }
                ActivityStack.getScreenManager().popOneActivity(GuideActivity.class);
            }
        };
        timer.schedule(task,6000);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.guide_skip:
                Intent intent=new Intent(baseContext,LoginActivity.class);
                Intent intent1=new Intent(baseContext,MainActivity.class);
                if (unionid.isEmpty()){
                    startActivity(intent);
                }else {
                    startActivity(intent1);
                }
                ActivityStack.getScreenManager().popOneActivity(GuideActivity.class);
                break;
        }
    }
}
